<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:pe="http://primefaces.org/ui/extensions">

<ui:composition template="/layouts/template.xhtml">
	<ui:define name="body">
		<style>
			.ui-datatable .ui-column-filter { display:block !important; margin:auto !important; width:80% !important; }
		</style>
	
		<h:form id="form" acceptcharset="ISO-8859-1">
			<f:metadata>
				<f:viewParam name="param" value="#{productionGroupBean.param}"/>
			</f:metadata>
			
			<p:panel header="#{msgs['massai.productionGroup.header.register']}">
				<h:panelGrid>
					<p:outputLabel value="#{msgs['massai.productionGroup.name']}" for="name" />
					<p:inputText id="name" tabindex="1" value="#{productionGroupBean.productionGroup.nameGroup}" 
						style="width: 350px;" maxlength="255" required="true" requiredMessage="Nome #{msgs['common.required.field']}" />
				</h:panelGrid>

				<h:panelGroup rendered="#{productionGroupBean.productionGroup.id ne null}">
					<h:panelGrid>
						<p:outputLabel for="copyProductionGroup" value="#{msgs['massai.productionGroup.copyProductionGroup']}" />
						<p:autoComplete id="copyProductionGroup" value="#{productionGroupBean.productionGroupComplete}"
							completeMethod="#{productionGroupBean.completeSearchProductionGroup}" var="productionGroup" itemLabel="#{productionGroup.nameGroup}" itemValue="#{productionGroup}"
							label="#{msgs['massai.productionGroup.copyProductionGroup']}" converter="entityConverter" minQueryLength="3" 
							maxResults="20" forceSelection="true" cacheTimeout="30000" autocomplete="true" size="49" tabindex="4" 
							emptyMessage="#{msgs['common.no.record.found']}">
							<p:ajax event="itemSelect" listener="#{productionGroupBean.onItemSelect}" update="panelGroupItem" />
						</p:autoComplete>
					</h:panelGrid>
	
					<h:panelGroup id="panelGroupItem">
						<p:spacer height="20px" />
					
						<fieldset style="padding: 10px;">
							<legend><p:outputLabel value="#{msgs['massai.productionGroup.listGroupItem']}" /></legend>
		
							<h:panelGrid columns="2" style="width: 100%;">	
								<h:panelGrid columns="3">
									<h:panelGrid>
										<p:outputLabel for="serviceItemDescription" value="#{msgs['massai.productionGroup.serviceItem']}" />
										<p:autoComplete id="serviceItemDescription" value="#{productionGroupBean.serviceItemComplete}"
											completeMethod="#{productionGroupBean.completeSearch}" var="itemComplete" itemLabel="#{itemComplete.description}" itemValue="#{itemComplete}"
											label="#{msgs['massai.productionGroup.serviceItem']}" converter="entityConverter" minQueryLength="3" 
											maxResults="20" forceSelection="true" cacheTimeout="30000" autocomplete="true" size="45" tabindex="4" 
											emptyMessage="#{msgs['common.no.record.found']}">
											<p:ajax event="itemSelect" listener="#{productionGroupBean.onItemSelect}" />
										</p:autoComplete>
									</h:panelGrid>
	
									<h:panelGrid>
										<p:outputLabel for="unitValue" value="#{msgs['massai.productionGroup.unitValue']}" />
										<p:inputText id="unitValue" value="#{productionGroupBean.unitValue}" 
											style="width: 80px; text-align: right;" label="#{msgs['massai.productionGroup.unitValue']}"
											maxlength="8" placeholder="#{msgs['placeholder.value']}" tabindex="5"
											onkeypress="return numberOnlyCurrency(this, event);">
											<f:convertNumber pattern="#,##0.00" currencySymbol="R$" maxFractionDigits="2" minFractionDigits="2" type="number" />
											<p:ajax event="change" global="false" update="unitValue" />
										</p:inputText>
									</h:panelGrid>
			
									<h:panelGrid style="float: right;">
										<p:spacer height="13" />
										<h:commandButton value="#{msgs['common.include']}" 
											style="margin-left: 5px; padding: 2px 8px; cursor: pointer; font-weight: bold; color: #4F4F4F;" 
											action="#{productionGroupBean.addGroupItem()}" type="button" tabindex="6">
											<f:ajax event="click" render="panelGroupItem" listener="#{productionGroupBean.addGroupItem()}" />
										</h:commandButton>
									</h:panelGrid>
								</h:panelGrid>
								
								<h:panelGrid style="float: right;">
									<h:outputLabel value="#{msgs['massai.productionGroup.applyPercentage.field']}" />
									<h:panelGroup>
										<p:inputText tabindex="7" style="width: 80px; text-align: right;"
											label="#{msg['massai.lancarServicoProducao.valorPerc']}" id="valurPercentage"
											maxlength="8" value="#{productionGroupBean.applyPercent}"
											onkeypress="return numberOnlyCurrency(this, event);">
											<p:ajax event="change" global="false" />
											<f:convertNumber pattern="#,##0.0000" 
												maxFractionDigits="4" minFractionDigits="4" type="number" />
										</p:inputText>
										
										<p:commandButton value="#{msgs['massai.productionGroup.applyPercentage']}" 
											style="margin-left: 5px;" actionListener="#{productionGroupBean.calculatingIncrease()}" 
											ajax="true" tabindex="8" update="form" />
									</h:panelGroup>
								</h:panelGrid>
							</h:panelGrid>
		
							<p:spacer height="10" />
		
							<p:dataTable id="dataTableGroupItem" emptyMessage="#{msgs['common.no.record.found']}" 
								value="#{productionGroupBean.productionGroup.groupItems}" var="item" sortMode="multiple" rows="10" paginator="true"
				                paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
				                currentPageReportTemplate="({currentPage} de {totalPages})" paginatorPosition="bottom" paginatorAlwaysVisible="false"
				                rowIndexVar="row" editable="true" editMode="cell" filteredValue="#{productionGroupBean.filtersItems}" filterEvent="enter">
				                
								<p:column headerText="#{msgs['massai.productionGroup.level']}" width="50" style="text-align: center;" sortBy="#{item.serviceItem.categoryLevel.codeInt}">
									<h:outputText tabindex="2" value="#{item.serviceItem.categoryLevel.code}.#{productionGroupBean.completedZerosLeft(item.serviceItem.levelService, 3)}" />
								</p:column>

								<p:column headerText="#{msgs['massai.productionGroup.description']}" sortBy="#{item.serviceItem.description}" 
									filterBy="#{item.serviceItem.description}" filterFunction="#{productionGroupBean.filterByDescription}">
									<h:outputText value="#{item.serviceItem.description}" />
								</p:column>

								<p:column headerText="#{msgs['massai.productionGroup.unitMeasure']}" sortBy="#{item.serviceItem.unitMeasure.acronym}" width="150">
									<h:outputText value="#{item.serviceItem.unitMeasure.acronym} - #{item.serviceItem.unitMeasure.nameMeasure}" />
								</p:column>
	
								<p:column headerText="#{msgs['massai.productionGroup.unitValue']}" sortBy="#{item.unitValue}" width="110" id="valueUnitColumn">
									<p:cellEditor>
										<f:facet name="output">
											<h:outputText value="#{item.unitValue}">
												<f:convertNumber pattern="#,##0.00" currencySymbol="R$" maxFractionDigits="2" minFractionDigits="2" type="number" />
											</h:outputText>
										</f:facet>
										<f:facet name="input">
											<p:inputText value="#{item.unitValue}" 
												style="width: 95%; text-align: right;" label="#{msgs['massai.productionGroup.unitValue']}" maxlength="8"
												onkeypress="return numberOnlyCurrency(this, event);">
												<f:convertNumber pattern="#,##0.00" currencySymbol="R$" maxFractionDigits="2" minFractionDigits="2" type="number" />
											</p:inputText>
										</f:facet>
									</p:cellEditor>
								</p:column>
	
								<p:ajax event="cellEdit" listener="#{productionGroupBean.onCellEdit}" update="dataTableGroupItem,valueUnitColumn" />
	
								<p:column headerText="#{msgs['common.delete']}" width="60" style="text-align: center;">
									<h:commandLink id="delete" tabindex="9" immediate="true"
										onclick="if (!window.confirm('Deseja excluir esse registro?') ) {return false}" 
						            	actionListener="#{productionGroupBean.deleteGroupItem(item, row)}">
										<img src="#{facesContext.externalContext.requestContextPath}/images/ico_remove.png" 
											width="16" height="16" border="0" name="#{msgs['common.delete']}" 
											alt="#{msgs['common.delete']}" id="icoRemove" title="#{msgs['common.delete']}" />
									</h:commandLink>
								</p:column>
							</p:dataTable>
						</fieldset>
					</h:panelGroup>
	
					<p:spacer height="30" />
	
					<fieldset style="padding: 10px;">
						<legend><p:outputLabel value="#{msgs['massai.productionGroup.listDepartment']}" /></legend>
	
						<p:dataTable id="dataTableDepartment" emptyMessage="#{msgs['common.no.record.found']}" 
							value="#{productionGroupBean.departments}" var="depart" sortMode="multiple" rows="10" paginator="true"
			                paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
			                currentPageReportTemplate="({currentPage} de {totalPages})" paginatorPosition="bottom" paginatorAlwaysVisible="false">
	
							<p:column headerText="#{msgs['massai.productionGroup.selection']}" width="30" style="text-align: center;">
								<p:selectBooleanCheckbox tabindex="10" value="#{depart.selected}">
									<p:ajax event="change" listener="#{productionGroupBean.associateDepartment(depart)}" update="dataTableDepartment" />
								</p:selectBooleanCheckbox>
							</p:column>
	
							<p:column headerText="#{msgs['massai.productionGroup.code']}" width="130">
								<h:outputText value="#{depart.codeEmp} - #{depart.codeDepartment}" />
							</p:column>
	
							<p:column headerText="#{msgs['massai.productionGroup.name']}" sortBy="#{depart.alternativeName}">
								<h:outputText value="#{depart.alternativeName}" />
							</p:column>
						</p:dataTable>
					</fieldset>
				</h:panelGroup>

				<p:spacer height="25px" />

				<h:panelGrid style="width: 100%;">
					<h:panelGrid style="float: right;" columns="2">
						<p:commandButton value="#{msgs['common.back']}" style="padding: 1px !important;"
							action="productionGroupConsult" ajax="false" immediate="true" tabindex="11" />

						<p:commandButton tabindex="12" value="#{msgs['common.save']}"
							actionListener="#{productionGroupBean.save()}" ajax="false" 
							style="margin-right: 5px;" styleClass="buttonSave" update=":form"
							rendered="#{sessionBean.showAction('supportProductionGroup', 'insert')}" />
					</h:panelGrid>
				</h:panelGrid>
			</p:panel>
		</h:form>
	</ui:define>
</ui:composition>
</html>